/**
 * @(#) ControlSimulatorComponent.java
 */

package pcsr.simulator.control;

import java.awt.Rectangle;
import java.awt.Shape;

public abstract class ControlSimulatorComponent implements Cloneable
{
	private String componetID;
	
	private String mode;
	
	private int height;
	
	private int width;
	
	private int xPos;
		
	private int yPos;
		
	protected int colisionID;
	
	protected RobotBrain mybrain;
	
	public ControlSimulatorComponent(String ID)
	{
		componetID = ID;
	}
	
	public boolean CheckCollision(ControlSimulatorComponent component)
	{
		Shape meRect = GetMyArea();
		Shape cmpRect = component.GetMyArea();

		if( meRect.intersects(cmpRect.getBounds2D()))
		{
			return true;
		}
		return false;
	}
	
	/**
	 * @return the height
	 */
	public int GetHeight() {
		return height;
	}
	
	public String GetID()
	{
		return componetID;
	}
	
	/**
	 * @return the width
	 */
	public int GetWidth() {
		return width;
	}
	
	/**
	 * @return the xPos
	 */
	public int GetXPos() {
		return xPos;
	}

	/**
	 * @return the yPos
	 */
	public int GetYPos() {
		return yPos;
	}

	public void ProcessCollision(ControlSimulatorComponent component)
	{
			Rectangle me = new Rectangle(
								this.GetXPos(), 
								this.GetXPos(), 
								this.GetWidth(), 
								this.GetHeight()
							);
			Rectangle him = new Rectangle(
								component.GetXPos(), 
								component.GetYPos(), 
								component.GetWidth(), 
								component.GetHeight()
							);
		
			me.intersection(him);
	}

	protected Object clone() throws CloneNotSupportedException {

		ControlSimulatorComponent clone=(ControlSimulatorComponent)super.clone();

		return clone;

	}

	/**
	 * @param height the height to set
	 */
	protected void setHeight(int height) {
		this.height = height;
	}

	/**
	 * @param width the width to set
	 */
	protected void setWidth(int width) {
		this.width = width;
	}

	/**
	 * @param xPos the xPos to set
	 */
	protected void setXPos(int xPos) {
		this.xPos = xPos;
	}

	/**
	 * @param yPos the yPos to set
	 */
	protected void setYPos(int yPos) {
		this.yPos = yPos;
	}
	
	
	Shape GetMyArea()
	{
		return new Rectangle(GetXPos(),GetYPos(),GetWidth(),GetHeight());
	}

	/**
	 * @param mode the mode to set
	 */
	protected void setMode(String mode) {
		this.mode = mode;
	}

	/**
	 * @return the mode
	 */
	protected String getMode() {
		return mode;
	}
	
}
